package vn.aptech.scrumgroup.model;

import vn.aptech.scrumgroup.util.DrawUtil;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;

public class ObjectSprintModel extends AbstractBaseModel{
	private float radius;
	private float cX;
	private float cY;
	private float mRadius;
	private float mcX;
	private float mcY;
	private float stroke;
	private float mStroke;
	private float rX;
	private float rY;
	private float rHeight;
	private float rwidth;
	private float blankStroke;
	private String sprint="Sprint";
	private String weeks="1-4 Weeks";
	//khoi tao cac diem can ve dua tren toa do trung tam duong tron lon va ban kinh duong tron lon
	public ObjectSprintModel(float cX, float cY, float radius, int backColor, int foreColor) {
		super(backColor, foreColor);
		this.radius = radius;
		this.cX = cX;
		this.cY = cY;
		this.stroke = radius / 3;
		this.mStroke = 0.7f * stroke;
		this.mRadius = radius / 2;
		float temp = ((float) Math.sqrt(2) / 2) * (1.5f) * radius;
		mcX = cX + temp;
		mcY = this.cY - temp;
		this.rX = cX - radius - stroke / 2;
		this.rY = cY + (radius - stroke / 2);
		rHeight = stroke;
		rwidth = (mcX + mRadius + mStroke / 2) - (cX - radius - stroke / 2);
		this.blankStroke = 2 * radius / 9;
		
	}
	//ham ve doi tuong sprint
//	public void draw(Canvas canvas) {
//		// TODO Auto-generated method stub
//		Paint paint=new Paint();
//		paint.setColor(textColor);
//		paint.setTextSize(radius/2);
//		paint.setStyle(Style.FILL_AND_STROKE);
//		paint.setStrokeWidth(2);
//		paint.getTextBounds(sprint, 0, sprint.length(), rect4);
//		
//		canvas.drawText(sprint, cX-rect4.width()/2, cY, paint);
//
//		paint.setTextSize(radius/4);
//		paint.setStyle(Style.FILL_AND_STROKE);
//		paint.setStrokeWidth(1);
//		paint.getTextBounds(weeks, 0, weeks.length(), rect5);
//		canvas.drawText(weeks, cX-rect5.width()/2, cY+rect5.height()*1.5f, paint);
//		
//		paint.setAntiAlias(true);
//		paint.setColor(shapeColor);
//		paint.setStyle(Style.FILL);
//		canvas.drawRect(rX, rY, rX + rwidth, rY + rHeight, paint);
//		paint.setStyle(Style.STROKE);
//		paint.setStrokeWidth(stroke);
//		
//		canvas.drawArc(rectF1, 150, 290, false, paint);
//		paint.setStrokeWidth(mStroke);
//		
//		canvas.drawArc(rectF2, 145, 277, false, paint);
//		
//		paint.setColor(Color.BLACK);
//		paint.setStrokeWidth(blankStroke);
//		canvas.drawArc(rectF3, 0, 90, false, paint);
//		paint.setColor(Color.RED);
//		paint.setStyle(Style.FILL);
//		drawTriangle(cX - (radius - stroke) * (float) Math.sqrt(3) / 2, cY
//				+ (radius - stroke) / 2,
//				cX - (radius + stroke) * (float) Math.sqrt(3) / 2, cY
//						+ (radius + stroke) / 2, cX - (radius - stroke)
//						* (float) Math.sqrt(3) / 2, cY + (radius + stroke) / 2,
//				canvas, paint);
//		drawTriangle(mcX + (mRadius - mStroke) / 2, mcY + (mRadius - mStroke)
//				* (float) Math.sqrt(3) / 2, mcX + (mRadius + mStroke) / 2, mcY
//				+ (mRadius + mStroke) * (float) Math.sqrt(3) / 2, mcX
//				+ (mRadius - mStroke) / 2, mcY + (mRadius + mStroke)
//				* (float) Math.sqrt(3) / 2, canvas, paint);
//		drawTriangle(rX + rwidth, rY - stroke / 2, rX + rwidth, rY + rHeight
//				+ stroke / 2, rX + rwidth + stroke / 2, rY + stroke / 2,
//				canvas, paint);
//		// Path path2 = new Path();
//		// path2.moveTo(400, 400);
//		// path2.lineTo(450, 450);
//		// paint.setColor(Color.CYAN);
//		// paint.setStyle(Style.STROKE);
//		// paint.setStrokeWidth(50);
//		// canvas.drawPath(path2, paint);
//		// paint.setColor(Color.MAGENTA);
//		// paint.setStyle(Style.FILL);
//		// paint.setStrokeWidth(5);
//		// canvas.drawPoint(400, 400, paint);
//		// canvas.drawPoint(450, 450, paint);
////		drawGlow(canvas, paint);
//	}
//ham ve tam giac dau mui ten
	public void drawTriangle(float x0, float y0, float x1, float y1, float x2,
			float y2, Canvas canvas, Paint paint) {

		Path path = new Path();
		path.moveTo(x0, y0);
		path.lineTo(x1, y1);
		path.lineTo(x2, y2);
		path.lineTo(x0, y0);
		path.close();
		canvas.drawPath(path, paint);
	}

	 

	//get set cho Cx,Cy,Radius,shapeColor,textColor

	public float getRadius() {
		return radius;
	}

	public void setRadius(float radius) {
		this.radius = radius;
	}

	public float getcX() {
		return cX;
	}

	public void setcX(float cX) {
		this.cX = cX;
	}

	public float getcY() {
		return cY;
	}

	public void setcY(float cY) {
		this.cY = cY;
	}


	@Override
	public boolean isPointOf(float x, float y) {
		// TODO Auto-generated method stub
		if(x>=rX&&x<=(rX+rwidth)&&y>=(mcY-mRadius)&&y<=(rY+rHeight)) return true;
		return false;
	}
	@Override
	public void changeColor(int color) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onDraw(Canvas c) {
		// TODO Auto-generated method stub
		Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		Rect rect = new Rect();
		
		//paint.setARGB(255, 51, 122, 162);
		paint.setColor(foreColor);
//		paint.setTextSize(radius/4);
		paint.setTextSize(DrawUtil.calculateTextSize(sprint, radius, paint, 3));
		paint.setStyle(Style.FILL_AND_STROKE);
		paint.setStrokeWidth(2);
		paint.getTextBounds(sprint, 0, sprint.length(), rect);
		
		c.drawText(sprint, cX-rect.width()/2, cY, paint);

//		paint.setTextSize(radius/4);
		paint.setTextSize(DrawUtil.calculateTextSize(weeks, radius, paint, 3));
		paint.setStyle(Style.FILL_AND_STROKE);
		paint.setStrokeWidth(1);
		paint.getTextBounds(weeks, 0, weeks.length(), rect);
		c.drawText(weeks, cX-rect.width()/2, cY+rect.height()*1.5f, paint);
//		c.drawText(weeks, cX-rect.width()/2, cY+rect.height()/2, paint);
		
		paint.setColor(backColor);
		paint.setStyle(Style.FILL);
		c.drawRect(rX, rY, rX + rwidth, rY + rHeight, paint);
		paint.setStyle(Style.STROKE);
		paint.setStrokeWidth(stroke);
		
		RectF rectF1 = new RectF(cX - radius, cY - radius, cX + radius, cY
				+ radius);
		c.drawArc(rectF1, 150, 290, false, paint);
		paint.setStrokeWidth(mStroke);
		
		RectF rectF2 = new RectF(mcX - mRadius, mcY - mRadius, mcX + mRadius,
				mcY + mRadius);
		c.drawArc(rectF2, 145, 277, false, paint);
		
		RectF rectF3 = new RectF(cX - radius - stroke / 2 - blankStroke / 2, cY
				- radius - stroke / 2 - blankStroke / 2, cX + radius + stroke
				/ 2 + blankStroke / 2, cY + radius + stroke / 2 + blankStroke
				/ 2);
		//paint.setColor(Color.WHITE);
		paint.setAlpha(0);
		paint.setStrokeWidth(blankStroke);
		c.drawArc(rectF3, 0, 90, false, paint);
		paint.setColor(backColor);
		paint.setStyle(Style.FILL);
		drawTriangle(cX - (radius - stroke) * (float) Math.sqrt(3) / 2, cY
				+ (radius - stroke) / 2,
				cX - (radius + stroke) * (float) Math.sqrt(3) / 2, cY
						+ (radius + stroke) / 2, cX - (radius - stroke)
						* (float) Math.sqrt(3) / 2, cY + (radius + stroke) / 2,
				c, paint);
		drawTriangle(mcX + (mRadius - mStroke) / 2, mcY + (mRadius - mStroke)
				* (float) Math.sqrt(3) / 2, mcX + (mRadius + mStroke) / 2, mcY
				+ (mRadius + mStroke) * (float) Math.sqrt(3) / 2, mcX
				+ (mRadius - mStroke) / 2, mcY + (mRadius + mStroke)
				* (float) Math.sqrt(3) / 2, c, paint);
		drawTriangle(rX + rwidth, rY - stroke / 2, rX + rwidth, rY + rHeight
				+ stroke / 2, rX + rwidth + stroke / 2, rY + stroke / 2,
				c, paint);
		// Path path2 = new Path();
		// path2.moveTo(400, 400);
		// path2.lineTo(450, 450);
		// paint.setColor(Color.CYAN);
		// paint.setStyle(Style.STROKE);
		// paint.setStrokeWidth(50);
		// canvas.drawPath(path2, paint);
		// paint.setColor(Color.MAGENTA);
		// paint.setStyle(Style.FILL);
		// paint.setStrokeWidth(5);
		// canvas.drawPoint(400, 400, paint);
		// canvas.drawPoint(450, 450, paint);
//		drawGlow(canvas, paint);
	}
	@Override
	public void onUpdate(double t) {
		// TODO Auto-generated method stub
		
	}
}
